
options(scipen=20)

library(MASS)
library(WhatIf)
library(RColorBrewer)
library(simcf)
library(verification)
library(foreign)
library(nnet)
library(xtable)
library(apsrtable)
library(ggplot2)
library(dplyr)
library(stargazer)
col <- brewer.pal(3,"Dark2")

anes<-read.dta("anes.dta")
anes<- anes %>% mutate(ai=protest+petition+don_rel+don_soc+community+meet+volunteer+official)

ncps<-read.dta("ncps.dta")
ncps<-ncps %>% mutate(ai=petition+community+meeting+org+letter+donate+dem+elect)

cols <- c('ai','prox2','pers','cpi','inteff','female','young','old','edu4','inc40','inc60','inc80','inc100','inc101',
            'incmis','polint','church','republican','independent','mode','nonwhite')
stargazer(
  ncps[, cols], 
  summary.stat = c("min", "p25", "mean", "p75", "max", "sd"),
  covariate.labels=c("Participation Index",
                     "Proximal Contact",
                     "Personal Contact",
                     "Injustice",
                     "Efficacy",
                     "Female","Age: 18-34","Age: 65+",
                     "Education","20k-40k","40k-60k","60k-80k","80k-100k","100k+",
                     "Missing Inc","Political Int","Religiosity",
                     "Republican","Independent","Mode","Nonwhite"),
  out = "ncps_descriptive.tex",
  title="Descriptive statistics of variables used in the NCPS",
  label="ncps_descriptive"
)



cols <- c('ai','prox2','pers','disc','inteff','female','young','old','edu4','inc40','inc60','inc80','inc100','inc101',
          'incmis','polint','church','republican','independent','nonwhite')
stargazer(
  anes[, cols], 
  summary.stat = c("min", "p25", "mean", "p75", "max", "sd"),
  covariate.labels=c("Participation Index",
                     "Proximal Contact",
                     "Personal Contact",
                     "Discrimination",
                     "Efficacy",
                     "Female","Age: 18-34","Age: 65+",
                     "Education","20k-40k","40k-60k","60k-80k","80k-100k","100k+",
                     "Missing Inc","Political Int","Religiosity",
                     "Republican","Independent","Nonwhite"),
  out = "anes_descriptive.tex",
  title="Descriptive statistics of variables used in the ANES",
  label="anes_descriptive"
)

prop.table(table(anes$ai))
prop.table(table(wncps$ai))
prop.table(table(nwncps$ai))

mean(nwncps$ai)
mean(wncps$ai)

